package cn.sdormitory.controller;

import cn.sdormitory.classHygiene.entity.AppClassHygiene;
import cn.sdormitory.classHygiene.req.ClassHygieneInfoReq;
import cn.sdormitory.classHygiene.vo.ClassHygieneVo;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.dto.ResultMsg;

import cn.sdormitory.service.AppClassroomHygieneService;
import cn.sdormitory.tencent.service.TencentCosFileService;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className: AppClassroomHygieneController
 * @author: Alex
 * @date: 2024/12/12
 **/
@Api("APP端教室卫生管理接口")
@RestController
@RequestMapping("/app/classroom/hygiene")
public class AppClassroomHygieneController {
	
	@Resource
	private AppClassroomHygieneService appClassroomHygieneService;
	
	@Autowired
	private TencentCosFileService cosFileService;
	
	@ApiOperation(value = "今日教室卫生检查情况")
	@GetMapping("/getTodayClassroomHygiene")
	public ResultMsg getTodayClassroomHygiene(String hygieneType, String checktime) {
		List<ClassHygieneVo> classHygieneVos = appClassroomHygieneService.getTodayClassroomHygiene(hygieneType, checktime);
		return  ResultMsg.BY_SUCCESS("获取成功", classHygieneVos);
	}
	
	@ApiOperation(value = "根据id和日期获取教室卫生详情")
	@GetMapping("/getClassHygieneById")
	public ResultMsg getClassHygieneById(String classHygieneId, String checkDate) {
		AppClassHygiene classHygieneVos = appClassroomHygieneService.getClassHygieneDetailById(classHygieneId, checkDate);
		return  ResultMsg.BY_SUCCESS("获取成功", classHygieneVos);
	}
	
	@ApiOperation(value = "当日卫生检查提交")
	@PostMapping("/submitHygiene")
	public CommonResult submitHygiene(@RequestBody ClassHygieneInfoReq hygieneInfoReq) {
		int result = appClassroomHygieneService.submitHygiene(hygieneInfoReq);
		if (result > 0) {
			return CommonResult.success();
		}
		return CommonResult.failed();
	}
	
	@ApiOperation(value = "上传班级卫生图片到腾讯云oos")
	@PostMapping("/uploadHygienePhoto")
	public CommonResult<String> uploadHygienePhoto(@RequestParam(value = "file") MultipartFile file) {
		String photo = cosFileService.uploadImg(file);
		Assert.notNull(photo,"上传卫生照片到腾讯云失败");
		return CommonResult.success(photo);
	}
}
